package com.studio701.carguard.service.imp;

import com.studio701.carguard.pojo.ReportOperation;
import com.studio701.carguard.mapper.ReportOperationMapper;
import com.studio701.carguard.service.IReportOperationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xjc
 * @since 2022-04-09
 */
@Service
public class ReportOperationServiceImpl extends ServiceImpl<ReportOperationMapper, ReportOperation> implements IReportOperationService {


    @Autowired
    ReportOperationMapper reportOperationMapper;



    @Override
    public int insert(ReportOperation reportOperation) {
        int high = 100, mid = 60, low = 10;
        BigDecimal score = BigDecimal.valueOf(0);
        if(reportOperation.getRoAbnormalspeed() == 0){
            score = score.add(new BigDecimal("23.04"));
        }else if(reportOperation.getRoAbnormalspeed() <= 3){
            score = score.add(new BigDecimal(String.valueOf(23.04*0.6)));
        }

        if(reportOperation.getRoBrakes() == 0){
            score = score.add(new BigDecimal("23.92"));
        }else if(reportOperation.getRoBrakes() <= 3){
            score = score.add(new BigDecimal(String.valueOf(23.92*0.6)));
        }

        if(reportOperation.getRoPedalchange() <= 5){
            score = score.add(new BigDecimal("8.92"));
        }else if(reportOperation.getRoPedalchange() <= 10){
            score = score.add(new BigDecimal(String.valueOf(8.92*0.6)));
        }

        if(reportOperation.getRoEnginespeedcontrol() > 70){
            score = score.add(new BigDecimal("8.67"));
        }else if(reportOperation.getRoEnginespeedcontrol() > 30 && reportOperation.getRoEnginespeedcontrol() < 70){
            score = score.add(new BigDecimal(String.valueOf(8.67*0.6)));
        }

        if(80 <= reportOperation.getRoCoolingfluidmaxtemperature() && reportOperation.getRoCoolingfluidmaxtemperature()  <= 95 && reportOperation.getRoCoolingfluidmintemperature() >= 80){
            score = score.add(new BigDecimal("7.48"));
        }else if(95 < reportOperation.getRoCoolingfluidmaxtemperature() && reportOperation.getRoCoolingfluidmaxtemperature() <= 100 && reportOperation.getRoCoolingfluidmintemperature() >= 80){
            score = score.add(new BigDecimal(String.valueOf(7.48*0.6)));
        }

        if(reportOperation.getRoFatiguedriving() == 0){
            score = score.add(new BigDecimal("5.28"));
        }else if(reportOperation.getRoFatiguedriving() <= 30){
            score = score.add(new BigDecimal(String.valueOf(5.28*0.6)));
        }

        if(reportOperation.getRoFailuredriving() == 0){
            score = score.add(new BigDecimal("22.69"));
        }else if(reportOperation.getRoFailuredriving() <= 30){
            score = score.add(new BigDecimal(String.valueOf(22.69*0.6)));
        }

        reportOperation.setRoScore(score);

        return reportOperationMapper.insert(reportOperation);
    }

    @Override
    public boolean updateById(ReportOperation entity) {
        int high = 100, mid = 60, low = 10;
        BigDecimal score = BigDecimal.valueOf(0);
        if(entity.getRoAbnormalspeed() == 0){
            score = score.add(new BigDecimal("23.04"));
        }else if(entity.getRoAbnormalspeed() <= 3){
            score = score.add(new BigDecimal(String.valueOf(23.04*0.6)));
        }

        if(entity.getRoBrakes() == 0){
            score = score.add(new BigDecimal("23.92"));
        }else if(entity.getRoBrakes() <= 3){
            score = score.add(new BigDecimal(String.valueOf(23.92*0.6)));
        }

        if(entity.getRoPedalchange() <= 5){
            score = score.add(new BigDecimal("8.92"));
        }else if(entity.getRoPedalchange() <= 10){
            score = score.add(new BigDecimal(String.valueOf(8.92*0.6)));
        }

        if(entity.getRoEnginespeedcontrol() > 70){
            score = score.add(new BigDecimal("8.67"));
        }else if(entity.getRoEnginespeedcontrol() > 30 && entity.getRoEnginespeedcontrol() < 70){
            score = score.add(new BigDecimal(String.valueOf(8.67*0.6)));
        }

        if(80 <= entity.getRoCoolingfluidmaxtemperature() && entity.getRoCoolingfluidmaxtemperature()  <= 95 && entity.getRoCoolingfluidmintemperature() >= 80){
            score = score.add(new BigDecimal("7.48"));
        }else if(95 < entity.getRoCoolingfluidmaxtemperature() && entity.getRoCoolingfluidmaxtemperature() <= 100 && entity.getRoCoolingfluidmintemperature() >= 80){
            score = score.add(new BigDecimal(String.valueOf(7.48*0.6)));
        }

        if(entity.getRoFatiguedriving() == 0){
            score = score.add(new BigDecimal("5.28"));
        }else if(entity.getRoFatiguedriving() <= 30){
            score = score.add(new BigDecimal(String.valueOf(5.28*0.6)));
        }

        if(entity.getRoFailuredriving() == 0){
            score = score.add(new BigDecimal("22.69"));
        }else if(entity.getRoFailuredriving() <= 30){
            score = score.add(new BigDecimal(String.valueOf(22.69*0.6)));
        }

        entity.setRoScore(score);
        return super.updateById(entity);
    }
}
